﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
public partial class Register : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
          
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        sercureCode.ValidateCaptcha(txtCode.Text);
        if (!sercureCode.UserValidated)
        {
            failCode.IsValid = false;
            return;
        }
        
        DTO.NguoiDungDto user = new DTO.NguoiDungDto();
        user.DiaChi = txtDiaChi.Text;
        user.DienThoai = txtDienThoai.Text;
        user.Email = txtEmail.Text;
        user.HoTen = txtHoTen.Text;
        user.MatKhau = txtPassword.Text;
        if (txtNgaySinh.Text == "")
            user.NgaySinh =DateTime.Parse("1/1/1800");
        else
            user.NgaySinh = DateTime.Parse(txtNgaySinh.Text);
        user.TenDangNhap = txtUsername.Text;
        user.LoaiNguoiDung = 2;
        user.Diem = 0;
        user.SoTaiKhoan = String.Empty;
        
       
        try
        {
            BUS.NguoiDungBus.ThemNguoiDung(user);
            sendMailActive(user);
            Response.Redirect("KetQuaDangNhap.aspx");
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }
    protected void sendMailActive(DTO.NguoiDungDto user)
    {
        MailMessage message = new MailMessage();
        message.IsBodyHtml = true;
        message.Subject = "Fashion Shop";
        message.Body = "Xin Chào "+user.HoTen+"<br/>";
         message.Body +="Cảm ơn quý khách đã tạo tài khoản ở trang web chúng tôi. Click vào link dưới này để kích hoạt tài khoản";
         message.Body += " <a href='http://localhost:3527/Website1/ActivePage.aspx?user=" + user.TenDangNhap + "'> http://localhost:3527/Website1/ActiveAccount.aspx?user=" + user.TenDangNhap + "</a>";
        message.To.Add(user.Email);
        BUS.Mail.MailSender sender = new BUS.Mail.MailSender();
        sender.SendMail(message);
    }

}
